<!doctype html>
<html class="no-js">

<head>
    <title>幼儿园</title>
    <#include "/boya/template/meta.html" />
</head>

<body>
    <#import "/boya/template/marc.html" as mc />
    <@mc.content>
        <div id="app" class="page">
            <div class="title">食品及原料进货索证台账登记本 /</div>
            <div style="margin-bottom: 10px; display: flex; align-items: center;">
                <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" unlink-panels="true" :default-value="new Date">
                </el-date-picker>
                <el-input v-model="supplier" placeholder="供货商" style="width: 210px;" clearable v-if="${school.role!0} == 1"></el-input>
                <el-select v-model="storageId" clearable filterable placeholder="产品名称">
                    <el-option v-for="item in storages" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
                <el-button @click="onSearch"><i class="el-icon-search"></i>搜索</el-button>
            </div>
            <div class="am-btn-group am-btn-group-sm btn-group">
                <button type="button" class="am-btn am-btn-default" @click="add"><i class="am-icon-plus"></i>&nbsp;新增记录</button>
                <button type="button" class="am-btn am-btn-default" @click="genExcel"><i class="am-icon-download"></i>&nbsp;下载表格</button>
            </div>
            <table class="am-table table">
                <thead>
                    <tr>
                        <th>采购日期</th>
                        <th>产品名称（含品牌）</th>
                        <th>产品规格</th>
                        <th>进货数量</th>
                        <th>产品批号</th>
                        <th>保质期限</th>
                        <th>供货商</th>
                        <th>供货商联系方式</th>
                        <th>是否有索证</th>
                        <th>送货人</th>
                        <th>验收人</th>
                        <th>单位</th>
                        <!-- <th>凭证下载</th> -->
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in list">
                        <td class="am-text-middle">{{ item.date }}</td>
                        <td class="am-text-middle">{{ item.storageName }}</td>
                        <td class="am-text-middle">{{ item.size }}</td>
                        <td class="am-text-middle">{{ item.count }}</td>
                        <td class="am-text-middle">{{ item.no }}</td>
                        <td class="am-text-middle">{{ item.exp }}</td>
                        <td class="am-text-middle">{{ item.supplier }}</td>
                        <td class="am-text-middle">{{ item.supplierTel }}</td>
                        <td class="am-text-middle">
                            <!-- <span v-if="item.prove == 1">食品许可证</span>
                            <span v-else-if="item.prove == 2">营业执照</span>
                            <span v-else-if="item.prove == 3">检验证明</span>
                            <span v-else-if="item.prove == 4">购物凭证</span>
                            <span v-else>无</span> -->
                            {{ item.prove }}
                        </td>
                        <td class="am-text-middle">{{ item.sender }}</td>
                        <td class="am-text-middle">{{ item.acceptor }}</td>
                        <td class="am-text-middle">{{ item.schoolName }}</td>
                        <!-- <td class="am-text-middle">
                            <a :href="item.attachment" v-if="item.attachment">下载</a>
                        </td> -->
                        <td class="am-text-middle">
                            <button class="am-btn am-btn-default am-btn-xs" @click="edit(item.id)">编辑</button>
                            <button class="am-btn am-btn-danger am-btn-xs" @click="del(item.id)"><i class="am-icon-trash"></i>&nbsp;删除</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <#include "/boya/template/page.html" />
        </div>
    </@mc.content>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                list: [],
                storages: [],
                dateRange: '',
                supplier: '',
                storageId: ''
            }
        },
        mounted: function() {
            var jsonStr = '${list!}';
            if (jsonStr != '') {
                this.list = ${list!}
            }
            var storageStr = '${storages!}';
            if (storageStr != '') {
                this.storages = ${storages!'[]'}
            }
            var supplier = '${supplier!""}'
            if (supplier != '') {
                this.supplier = supplier;
            }
            var storageId = '${storageId!""}'
            if (storageId != '') {
                this.storageId = Number(storageId);
            }
            var startTime = '${startTime!""}'
            if (startTime != '') {
                this.dateRange = new Array;
                this.dateRange.push('${startTime!}');
                this.dateRange.push('${endTime!}');
            }
        },
        methods: {
            add() {
                window.location.href = "/boya/importInfo";
            },
            edit(id) {
                window.location.href = "/boya/importInfo?id=" + id;
            },
            del(id) {
                confirm("确认删除？", function() {
                    var param = Qs.stringify({
                        id: id
                    });
                    axios({
                        url: '/boya/delImport',
                        method: 'post',
                        data: param,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        }
                    })
                    .then(function(response) {
                        if (response.data.status == 200) {
                            // msg("删除成功");
                            window.location.reload();
                        } else {
                            msg(response.data.msg);
                            console.log(response.data);
                        }
                    })
                    .catch(function(error) {
                        msg("删除失败");
                        console.log(error);
                    });
                })
            },
            genExcel() {
                // console.log(window.location.pathname + window.location.search);
                // window.location.href = '/boya/downloadImportList';
                goDownload();
                //"营业执照" ,"食品经营许可证", "食品流通许可证" ,"检验证明", "购物凭证"
            },
            onSearch() {
                var self = this;
                var keys = [
                    { key: 'supplier', value: self.supplier },
                    { key: 'storageId', value: self.storageId }
                ]
                if (self.dateRange != null && self.dateRange.length > 1) {
                    keys.push({ key: 'startDate', value: self.dateRange[0] });
                    keys.push({ key: 'endDate', value: self.dateRange[1] });
                } else {
                    keys.push({ key: 'startDate', value: '' });
                    keys.push({ key: 'endDate', value: '' });
                }
                goPage(1, keys);
            },
            onPageChange(val) {
                goPage(val);
            }
        }
    })
    </script>
    <style type="text/css">
    .page {
        padding: 15px;
    }

    .title {
        margin-bottom: 10px;
        font-size: 1.2em;
    }

    .btn-group {
        margin-bottom: 10px;
    }

    .table {
        /*width: auto;*/
    }

    .no-border {
        border: none;
    }
    </style>
</body>

</html>